package com.usian.controller;

import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesisResult;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.usian.service.TongYiService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.example.ai.result.Result;
import org.example.ai.util.AuthContextHolder;
import org.example.dialogue.form.MessageForm;
import org.example.dialogue.vo.MessageVo;
import org.springframework.ai.image.ImageResponse;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;
import java.util.List;

/**
 * @author zqtao
 */
@Slf4j
@RestController
@RequestMapping("/tongyi/")
@CrossOrigin
public class TongYiController {

    @Resource
    private TongYiService tongYiService;


    @Operation(summary = "调用通义千问AI大模型实现文生图")
    @RequestMapping("/ai")
    public List<MessageVo> genImg(@RequestBody List<MessageForm> messageForms){
        ImageResponse imageResponse = tongYiService.genImg(messageForms);
        String url =imageResponse.getResult().getOutput().getUrl();
        MessageVo messageVo = new MessageVo();
        messageVo.setRole("assistant");
        messageVo.setContent(url);
        return Collections.singletonList(messageVo);
    }

}
